<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>【转帖】iOS中的数据解析 | 素墨文胤</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="转自：http://devlxx.com/ioskai-fa-zhong-de-shu-ju-chu-li/在一般的iOS中，有很大部分是把从服务端获取到的数据加载到UI上。但是在这个过程中如果处理，才能达到良好的可读性、可扩展、低耦合等效果类？
现在iOS中很大部分都是对JSON数据的处理，所以本文主要拿JSON进行说明。">
<meta property="og:type" content="article">
<meta property="og:title" content="【转帖】iOS中的数据解析">
<meta property="og:url" content="http://godera.org/2015/04/09/iOS中的数据解析/index.html">
<meta property="og:site_name" content="素墨文胤">
<meta property="og:description" content="转自：http://devlxx.com/ioskai-fa-zhong-de-shu-ju-chu-li/在一般的iOS中，有很大部分是把从服务端获取到的数据加载到UI上。但是在这个过程中如果处理，才能达到良好的可读性、可扩展、低耦合等效果类？
现在iOS中很大部分都是对JSON数据的处理，所以本文主要拿JSON进行说明。">
<meta property="og:updated_time" content="2015-11-18T03:22:11.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【转帖】iOS中的数据解析">
<meta name="twitter:description" content="转自：http://devlxx.com/ioskai-fa-zhong-de-shu-ju-chu-li/在一般的iOS中，有很大部分是把从服务端获取到的数据加载到UI上。但是在这个过程中如果处理，才能达到良好的可读性、可扩展、低耦合等效果类？
现在iOS中很大部分都是对JSON数据的处理，所以本文主要拿JSON进行说明。">
  
  
    <link rel="icon" href="/favicon.png">
  

  <link rel="stylesheet" href="/css/style.css">
  
    <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  
  
    <link rel="stylesheet" href="/scrollLoading/style.css">
  
  


  

  
    <link href='//fonts.useso.com/css?family=Titillium+Web:300,400,600' rel='stylesheet' type='text/css'>
    <link href="//fonts.useso.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
</head>

<body>
  <div id="wrap">
    <header id="header">
  <div id="header-outer" class="outer">
    <div class="container">
      <div class="container-inner">
        <div id="header-title">
          <h1 class="logo-wrap">
            <a href="/" class="logo"></a>
          </h1>
          
            <h2 class="subtitle-wrap">
              <p class="subtitle">一日心静一日仙，不以神力乱人间。</p>
            </h2>
          
        </div>
        <div id="header-inner" class="nav-container">
          <a id="main-nav-toggle" class="nav-icon fa fa-bars"></a>
          <div class="nav-container-inner">
            <ul id="main-nav">
              
                <li class="main-nav-list-item" ><a class="main-nav-list-link" href="/">Home</a></li>
              
                    <ul class="main-nav-list"><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/JS/">JS</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/Unix-Linux/">Unix_Linux</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/iOS/">iOS</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/哲学辨思/">哲学辨思</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/数据库/">数据库</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/文字文化/">文字文化</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/生活感悟/">生活感悟</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/随心随性/">随心随性</a></li><li class="main-nav-list-item"><a class="main-nav-list-link" href="/categories/默认标签/">默认标签</a></li></ul>
                  
                <li class="main-nav-list-item" ><a class="main-nav-list-link" href="/about/index.html">About</a></li>
              
            </ul>
            <nav id="sub-nav">
              <div id="search-form-wrap">
                
                  <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><input type="hidden" name="sitesearch" value="http://godera.org"></form>
                
              </div>
            </nav>
          </div>
        </div>
      </div>
    </div>
  </div>
</header>
    <div class="container">
      <div class="main-body container-inner">
        <div class="main-body-inner">
          <section id="main">
            <div class="main-body-header">

              <h1 class="header"><a class="page-title-link" href="/categories/iOS/">iOS</a></h1>
            </div>
            <div class="main-body-content">
              
  <article id="post-iOS中的数据解析" class="article article-single article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
      <!--  -->
      
        <header class="article-header">
          
  
    <h1 class="article-title" itemprop="name">
      【转帖】iOS中的数据解析
    </h1>
  

        </header>
      
      <p class="article-byline">
        <a href="/2015/04/09/iOS中的数据解析/" class="article-date">
  <time datetime="2015-04-09T11:37:08.000Z" itemprop="datePublished">2015-04-09</time>
</a>
      </p>
      <div class="article-entry" itemprop="articleBody">
        <p>转自：<a href="http://devlxx.com/ioskai-fa-zhong-de-shu-ju-chu-li/" target="_blank" rel="external">http://devlxx.com/ioskai-fa-zhong-de-shu-ju-chu-li/</a><br>在一般的iOS中，有很大部分是把从服务端获取到的数据加载到UI上。但是在这个过程中如果处理，才能达到良好的可读性、可扩展、低耦合等效果类？</p>
<p>现在iOS中很大部分都是对JSON数据的处理，所以本文主要拿JSON进行说明。<br><a id="more"></a><br>1、NSNull造成的Crash<br>记得在刚开始学习iOS的时候，有一次程序莫名Crash掉了。检查后发现原来是本来返回的数据是NSString的，结果解析后得到的是一个NSNull对象，然后将其赋值给一个UILabel对象的text，然后就造成NSInvalidArgumentException异常导致crash。相信不少开发者，都被NSNull坑过，最常见的是服务器返回的json里面，说好的字典、数组、数字，结果返回的是空值。 我们一般做一次类型判断：</p>
<h1 id="pragma_mark_-_如果为NSNull,则转换为nil">pragma mark - 如果为NSNull,则转换为nil</h1><ul>
<li>(id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict<br>{<br>  id object = [dict objectForKey:aKey];<br>  return [object isEqual:[NSNull null]] ? nil : object;<br>}</li>
</ul>
<p>//解析数据<br>self.title = [self objectOrNilForKey:@”title” fromDictionary:dict];<br>这样就不会出现把NSNull当做NSString、NSNumber、NSArray等操作而造成的Crash。 后来感觉这个不够优雅，就把它改成了Category（也可改成宏）:</p>
<p>@interface NSDictionary (TypeChecking)</p>
<ul>
<li>(id)objectOrNilForKey:(id)aKey;</li>
</ul>
<p>@end</p>
<p>@implementation NSDictionary (TypeChecking)</p>
<ul>
<li>(id)objectOrNilForKey:(id)aKey<br>{<br>  id object = [self objectForKey:aKey];<br>  return [object isEqual:[NSNull null]] ? nil : object;<br>}</li>
</ul>
<p>@end</p>
<p>//使用<br>self.title = [dict objectOrNilForKey:@”title”];<br>但是后来，了解了OC强大的Runtime。发现原来利用Rumtime我们可以更优雅的处理这个问题：</p>
<h1 id="define_NSNullObjects_@[@””,@0,@{},@[]]">define NSNullObjects @[@””,@0,@{},@[]]</h1><p>@interface NSNull (InternalNullExtention)<br>@end </p>
<p>@implementation NSNull (InternalNullExtention) </p>
<ul>
<li><p>(NSMethodSignature<em>)methodSignatureForSelector:(SEL)selector<br>{<br>  NSMethodSignature</em> signature = [super methodSignatureForSelector:selector];<br>  if (!signature) { </p>
<pre><code><span class="keyword">for</span> (<span class="type">NSObject</span> *<span class="class"><span class="keyword">object</span> <span class="title">in</span> <span class="title">NSNullObjects</span>) {</span> 
    signature = [<span class="class"><span class="keyword">object</span> <span class="title">methodSignatureForSelector</span>:</span>selector]; 
    <span class="keyword">if</span> (signature) { 
        <span class="keyword">break</span>; 
    } 
} 
</code></pre><p>  }<br>  return signature;<br>} </p>
</li>
<li><p>(void)forwardInvocation:(NSInvocation <em>)anInvocation<br>{<br>  SEL aSelector = [anInvocation selector];<br>  for (NSObject </em>object in NSNullObjects) { </p>
<pre><code><span class="keyword">if</span> ([<span class="class"><span class="keyword">object</span> <span class="title">respondsToSelector</span>:</span>aSelector]) { 
    [anInvocation invokeWithTarget:<span class="class"><span class="keyword">object</span>];</span>
    <span class="keyword">return</span>; 
} 
</code></pre><p>  }<br>  [self doesNotRecognizeSelector:aSelector];<br>}<br>@end<br>很高端的做法，通过消息转发机制来解决这个问题。如果无法理解这段代码的含义，我们可以看这篇博文Objective-C Runtime。</p>
</li>
</ul>
<p>常规数据解析的不足<br>假如我们有这样一段JSON数据：</p>
<p>{<br>  “lng” : 121.480263,<br>  “dataSource” : “SHANGHAI”,<br>  “lat” : 31.236295,<br>  “menus” : “测试”,<br>  “name” : “上海”<br>}<br>我们一般是创建一个对应的实体类来解析：</p>
<p>@interface City : NSObject <nscoding, nscopying=""></nscoding,></p>
<p>@property (nonatomic, assign) double lng;<br>@property (nonatomic, strong) NSString <em>dataSource;<br>@property (nonatomic, assign) double lat;<br>@property (nonatomic, strong) NSString </em>menus;<br>@property (nonatomic, strong) NSString *name;</p>
<ul>
<li>(instancetype)modelObjectWithDictionary:(NSDictionary *)dict;</li>
</ul>
<ul>
<li>(instancetype)initWithDictionary:(NSDictionary *)dict;</li>
<li>(NSDictionary *)dictionaryRepresentation;</li>
</ul>
<p>@end</p>
<h1 id="import_“City-h”">import “City.h”</h1><p>NSString <em>const kCityLng = @”lng”;<br>NSString </em>const kCityDataSource = @”dataSource”;<br>NSString <em>const kCityLat = @”lat”;<br>NSString </em>const kCityMenus = @”menus”;<br>NSString *const kCityName = @”name”;</p>
<p>@interface City ()</p>
<ul>
<li>(id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;</li>
</ul>
<p>@end</p>
<p>@implementation City</p>
<p>@synthesize lng = _lng;<br>@synthesize dataSource = _dataSource;<br>@synthesize lat = _lat;<br>@synthesize menus = _menus;<br>@synthesize name = _name;</p>
<ul>
<li>(instancetype)modelObjectWithDictionary:(NSDictionary *)dict<br>{<br>  return [[self alloc] initWithDictionary:dict];<br>}</li>
</ul>
<ul>
<li><p>(instancetype)initWithDictionary:(NSDictionary *)dict<br>{<br>  self = [super init];</p>
<p>  if(self &amp;&amp; [dict isKindOfClass:[NSDictionary class]]) {</p>
<pre><code><span class="keyword">self</span>.lng = [[<span class="keyword">self</span> <span class="symbol">objectOrNilForKey:</span>kCityLng <span class="symbol">fromDictionary:</span>dict] doubleValue];
<span class="keyword">self</span>.dataSource = [<span class="keyword">self</span> <span class="symbol">objectOrNilForKey:</span>kCityDataSource <span class="symbol">fromDictionary:</span>dict];
<span class="keyword">self</span>.lat = [[<span class="keyword">self</span> <span class="symbol">objectOrNilForKey:</span>kCityLat <span class="symbol">fromDictionary:</span>dict] doubleValue];
<span class="keyword">self</span>.menus = [<span class="keyword">self</span> <span class="symbol">objectOrNilForKey:</span>kCityMenus <span class="symbol">fromDictionary:</span>dict];
<span class="keyword">self</span>.name = [<span class="keyword">self</span> <span class="symbol">objectOrNilForKey:</span>kCityName <span class="symbol">fromDictionary:</span>dict];
</code></pre><p>  }</p>
<p>  return self;</p>
</li>
</ul>
<p>}</p>
<ul>
<li><p>(NSDictionary <em>)dictionaryRepresentation<br>{<br>  NSMutableDictionary </em>mutableDict = [NSMutableDictionary dictionary];<br>  [mutableDict setValue:[NSNumber numberWithDouble:self.lng] forKey:kCityLng];<br>  [mutableDict setValue:self.dataSource forKey:kCityDataSource];<br>  [mutableDict setValue:[NSNumber numberWithDouble:self.lat] forKey:kCityLat];<br>  [mutableDict setValue:self.menus forKey:kCityMenus];<br>  [mutableDict setValue:self.name forKey:kCityName];</p>
<p>  return [NSDictionary dictionaryWithDictionary:mutableDict];<br>}</p>
</li>
<li><p>(NSString *)description<br>{<br>  return [NSString stringWithFormat:@”%@”, [self dictionaryRepresentation]];<br>}</p>
</li>
</ul>
<h1 id="pragma_mark_-_Helper_Method">pragma mark - Helper Method</h1><ul>
<li>(id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict<br>{<br>  id object = [dict objectForKey:aKey];<br>  return [object isEqual:[NSNull null]] ? nil : object;<br>}</li>
</ul>
<h1 id="pragma_mark_-_NSCoding_Methods">pragma mark - NSCoding Methods</h1><ul>
<li><p>(id)initWithCoder:(NSCoder *)aDecoder<br>{<br>  self = [super init];<br>  self.lng = [aDecoder decodeDoubleForKey:kCityLng];<br>  self.dataSource = [aDecoder decodeObjectForKey:kCityDataSource];<br>  self.lat = [aDecoder decodeDoubleForKey:kCityLat];<br>  self.menus = [aDecoder decodeObjectForKey:kCityMenus];<br>  self.name = [aDecoder decodeObjectForKey:kCityName];<br>  return self;<br>}</p>
</li>
<li><p>(void)encodeWithCoder:(NSCoder *)aCoder<br>{<br>  [aCoder encodeDouble:_lng forKey:kCityLng];<br>  [aCoder encodeObject:_dataSource forKey:kCityDataSource];<br>  [aCoder encodeDouble:_lat forKey:kCityLat];<br>  [aCoder encodeObject:_menus forKey:kCityMenus];<br>  [aCoder encodeObject:_name forKey:kCityName];<br>}</p>
</li>
<li><p>(id)copyWithZone:(NSZone <em>)zone<br>{<br>  City </em>copy = [[City alloc] init];<br>  if (copy) {</p>
<pre><code><span class="keyword">copy</span><span class="variable">.lng</span> = <span class="keyword">self</span><span class="variable">.lng</span>;
<span class="keyword">copy</span><span class="variable">.dataSource</span> = [<span class="keyword">self</span><span class="variable">.dataSource</span> copyWithZone:zone];
<span class="keyword">copy</span><span class="variable">.lat</span> = <span class="keyword">self</span><span class="variable">.lat</span>;
<span class="keyword">copy</span><span class="variable">.menus</span> = [<span class="keyword">self</span><span class="variable">.menus</span> copyWithZone:zone];
<span class="keyword">copy</span><span class="variable">.name</span> = [<span class="keyword">self</span><span class="variable">.name</span> copyWithZone:zone];
</code></pre><p>  }<br>  return copy;<br>}<br>@end<br>虽然说， 有这样的工具(JSON Accelerator)直接根据JSON来生成对应的类，但是我现在能想到的就有这些问题存在:</p>
</li>
</ul>
<p>如果突然服务端说要加/减几个字段，改比较麻烦。<br>生成大量的同类型代码，不好维护<br>类嵌类的时候容易导致死循环<br>数据转换处理麻烦。如NSNumber直接转NSString，会出现精度问题。<br>其他问题。<br>那么我们如何解决这个问题类？</p>
<p>解决方案<br>在上面的City类中，我们可以发现，这其实是一个模板。如果我们根据这个模板去生成各种类，那么就会存在大量类似的代码。 那么我们如何把他们优雅的聚合在一起，做到高内聚，低耦合类？ 答案就是Runtime。 而且轮子别人已经帮我们做好了。 现在在Github上有三个关于这方面的库是比较好的。分别是MJExtension、JSONModel、Mantle。他们的作用都是用于JSON解析。</p>
<p>Mantle 是老牌的，使用人数最多，久经考验。<br>JSONModel 使用人数居中，带有网络请求部分。<br>MJExtention 开源不久，但是使用人数也不少，性能最好，使用最简单（不需要你的模型类继承任何特殊基类，毫无污染，毫无侵入性），而且开源者是中国的，交流也比较方便。<br>在这里JSONModel及Mantle就不做介绍了，就对MJExtention做一个简单的说明，有兴趣的话可以点击链接直接在Github上看官方的文档，是中文的，而且写的很详细。 下面依然拿City类做例子：</p>
<p>简单使用<br>//只需要引入头文件，就可以使用这个库的各个方法了。</p>
<h1 id="import_“MJExtension-h”">import “MJExtension.h”</h1><p>@interface City : NSObject</p>
<p>@property (nonatomic, assign) double lng;<br>@property (nonatomic, strong) NSString <em>dataSource;<br>@property (nonatomic, assign) double lat;<br>@property (nonatomic, strong) NSString </em>menus;<br>@property (nonatomic, strong) NSString *name;</p>
<p>@end</p>
<h1 id="import_“City-h”-1">import “City.h”</h1><p>@implementation City</p>
<p>@end<br>只需要这样就可以实现上面那个类的全部功能了。</p>
<p>字段转模型<br>// 将字典转City模型<br>City <em>city = [City objectWithKeyValues:dict];<br>将模型转为字典<br>// 新建模型<br>City </em>city = [[City alloc] init];<br>city.dataSource = @”SHANGHAI”;<br>city.menus = @”测试”;<br>city.name = @”上海”;<br>city.lng = 121.480263;<br>city.lat = 31.236295;</p>
<p>// 将模型转为字典<br>NSDictionary <em>cityDict = city.keyValues;<br>NSLog(@”%@”, cityDict);<br>/</em><br>{<br>  “lng” : 121.480263,<br>  “dataSource” : “SHANGHAI”,<br>  “lat” : 31.236295,<br>  “menus” : “测试”,<br>  “name” : “上海”<br>}<br>*/<br>当然这些都只是简单用法，这个库还支持这些功能：</p>
<p>字典数组（JSON Array） —&gt; 模型数组（Model Array）<br>模型数组（Model Array） —&gt; 字典数组（JSON Array）<br>模型中嵌套模型<br>模型中有个数组属性，数组里面又要装着其他模型<br>模型中的属性名和字典中的key不相同(或者需要多级映射)<br>更多用法请参考对应的文档及自己摸索咯。</p>

      </div>
      <footer class="article-footer">
        <a data-url="http://godera.org/2015/04/09/iOS中的数据解析/" data-id="ciw7o5qic00263refycjxl9vc" class="article-share-link"><i class="fa fa-share"></i>Share</a>
        
        
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/iOS/">iOS</a></li></ul>

      </footer>
    </div>
  </article>
  
  


<!--高速版-->
<div id="SOHUCS"></div>
<script charset="utf-8" type="text/javascript" src="http://changyan.sohu.com/upload/changyan.js" ></script>
<script type="text/javascript">
    window.changyan.api.config({
        appid: 'cys5Qvajj',
        conf: 'prod_62197afb84b42bd16c642feedaaef9f1'
    });
</script>   

            </div>
          </section>
          <aside id="sidebar">
  <a class="sidebar-toggle" title="Expand Sidebar"><i class="toggle icon"></i></a>
  <div class="sidebar-top">
    <p>follow:</p>
    <ul class="social-links">
      
        <li><a class="social-tooltip" title="github" href="https://github.com/godera" target="_blank"><i class="icon fa fa-github"></i></a></li>
      
    </ul>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2015/04/27/走到哪里、哪里就是我的家/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">newer</strong>
      <p class="article-nav-title">
        
          走到哪里、哪里就是我的家
        
      </p>
      <i class="icon fa fa-chevron-right" id="icon-chevron-right"></i>
    </a>
  
  
    <a href="/2015/04/03/公司的绩效考核制度终于颁布了/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">older</strong>
      <p class="article-nav-title">公司的绩效考核制度终于颁布了</p>
      <i class="icon fa fa-chevron-left" id="icon-chevron-left"></i>
    </a>
  
</nav>

  
  <div class="widgets-container">
    
      
  <div class="widget-wrap">
    <h3 class="widget-title">recents</h3>
    <div class="widget">
      <ul id="recent-post" class="">
        
          <li>
            
            <div class="item-thumbnail">
              
<a href="/2016/11/30/Markdown-技巧汇总（持续帖）/" class="thumbnail">
  
    <span class="thumbnail-image thumbnail-none"></span>
  
</a>

            </div>
            
            <div class="item-inner">
              <p class="item-category"><a class="article-category-link" href="/categories/iOS/">iOS</a></p>
              <p class="item-title"><a href="/2016/11/30/Markdown-技巧汇总（持续帖）/" class="title">Markdown 技巧汇总（持续帖）</a></p>
              <p class="item-date"><time datetime="2016-11-30T05:10:18.000Z" itemprop="datePublished">2016-11-30</time></p>
            </div>
          </li>
        
          <li>
            
            <div class="item-thumbnail">
              
<a href="/2016/11/27/CocoaPods-指南/" class="thumbnail">
  
    <span class="thumbnail-image thumbnail-none"></span>
  
</a>

            </div>
            
            <div class="item-inner">
              <p class="item-category"><a class="article-category-link" href="/categories/iOS/">iOS</a></p>
              <p class="item-title"><a href="/2016/11/27/CocoaPods-指南/" class="title">CocoaPods 指南</a></p>
              <p class="item-date"><time datetime="2016-11-27T11:03:26.000Z" itemprop="datePublished">2016-11-27</time></p>
            </div>
          </li>
        
          <li>
            
            <div class="item-thumbnail">
              
<a href="/2016/04/16/OC-和-Swift-的混用方法/" class="thumbnail">
  
    <span class="thumbnail-image thumbnail-none"></span>
  
</a>

            </div>
            
            <div class="item-inner">
              <p class="item-category"><a class="article-category-link" href="/categories/iOS/">iOS</a></p>
              <p class="item-title"><a href="/2016/04/16/OC-和-Swift-的混用方法/" class="title">OC 和 Swift 的混用方法</a></p>
              <p class="item-date"><time datetime="2016-04-16T11:11:42.000Z" itemprop="datePublished">2016-04-16</time></p>
            </div>
          </li>
        
          <li>
            
            <div class="item-thumbnail">
              
<a href="/2016/04/11/ReactiveCocoa-简单总结/" class="thumbnail">
  
    <span class="thumbnail-image thumbnail-none"></span>
  
</a>

            </div>
            
            <div class="item-inner">
              <p class="item-category"><a class="article-category-link" href="/categories/iOS/">iOS</a></p>
              <p class="item-title"><a href="/2016/04/11/ReactiveCocoa-简单总结/" class="title">ReactiveCocoa 简单总结</a></p>
              <p class="item-date"><time datetime="2016-04-11T03:00:29.000Z" itemprop="datePublished">2016-04-11</time></p>
            </div>
          </li>
        
          <li>
            
            <div class="item-thumbnail">
              
<a href="/2016/04/09/从汉语字面理解-观察者模式-和-订阅者模式-的区别/" class="thumbnail">
  
    <span class="thumbnail-image thumbnail-none"></span>
  
</a>

            </div>
            
            <div class="item-inner">
              <p class="item-category"><a class="article-category-link" href="/categories/Unix-Linux/">Unix_Linux</a></p>
              <p class="item-title"><a href="/2016/04/09/从汉语字面理解-观察者模式-和-订阅者模式-的区别/" class="title">从汉语字面理解 观察者模式 和 订阅者模式 的区别</a></p>
              <p class="item-date"><time datetime="2016-04-09T10:19:20.000Z" itemprop="datePublished">2016-04-09</time></p>
            </div>
          </li>
        
      </ul>
    </div>
  </div>

    
      
  <div class="widget-wrap widget-list">
    <h3 class="widget-title">archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/11/">November 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">April 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">March 2016</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/02/">February 2016</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">December 2015</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">October 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">September 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">August 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">June 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">May 2015</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">April 2015</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/03/">March 2015</a><span class="archive-list-count">36</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/02/">February 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/01/">January 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/06/">June 2012</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2011/10/">October 2011</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2010/06/">June 2010</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2008/08/">August 2008</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget-wrap widget-float">
    <h3 class="widget-title">tag cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/JS/" style="font-size: 10px;">JS</a> <a href="/tags/Unix-Linux/" style="font-size: 14px;">Unix_Linux</a> <a href="/tags/iOS/" style="font-size: 20px;">iOS</a> <a href="/tags/哲学辨思/" style="font-size: 16px;">哲学辨思</a> <a href="/tags/数据库/" style="font-size: 10px;">数据库</a> <a href="/tags/文字文化/" style="font-size: 18px;">文字文化</a> <a href="/tags/生活感悟/" style="font-size: 14px;">生活感悟</a> <a href="/tags/随心随性/" style="font-size: 12px;">随心随性</a> <a href="/tags/默认标签/" style="font-size: 10px;">默认标签</a>
    </div>
  </div>


    
      
  <div class="widget-wrap widget-list">
    <h3 class="widget-title">links</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="http://hexo.io">Hexo</a>
          </li>
        
      </ul>
    </div>
  </div>


    
  </div>
</aside>
        </div>
      </div>
    </div>
    <footer id="footer">
  
  <div class="container">
    <div class="container-inner">
      <a id="back-to-top" href="javascript:;"><i class="icon fa fa-angle-up"></i></a>
      <div class="credit">
        <h1 class="logo-wrap">
          <a href="/" class="logo"></a>
        </h1>
        <p>&copy; 2016 梁逊</p>
        <p>Powered by <a href="//hexo.io/" target="_blank">Hexo</a>. Theme by <a href="//github.com/ppoffice" target="_blank">PPOffice</a></p>
      </div>
    </div>
  </div>
</footer>
    


  <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>



  <script src="/fancybox/jquery.fancybox.pack.js"></script>



  <script src="/scrollLoading/jquery.scrollLoading.js"></script>
  <script src="/scrollLoading/main.js"></script>




<script src="/js/html-patch.js"></script>
<script src="/js/script.js"></script>

  </div>
</body>
</html>
